package com.example.mybaitsplusdemo;

import com.example.mybaitsplusdemo.entity.User;
import com.example.mybaitsplusdemo.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest
public class MyBaitsTestService {
    @Autowired
    private UserService userService;
    @Test
    public void Test(){

        User result= userService.getById(1);
        System.out.println("result"+result);

        int count=userService.count();
        System.out.println("count: "+count);
    }

    //批量添加
    @Test
    public void testInsertMore(){
        List<User> list=new ArrayList<>();
        for(int i=1;i<=10;i++){
            User user=new User();
            user.setAge(i+20);
            user.setName("a"+i);

            list.add(user);
        }
        boolean result=userService.saveBatch(list);
        System.out.println("result: "+result);
    }
}
